package com.un.ebs.order.task;

import com.un.ebs.core.UserContext;
import com.un.ebs.core.util.SecurityUtils;
import com.un.ebs.core.util.StringUtils;
import com.un.ebs.order.domain.OrderExt;
import com.un.ebs.order.service.OrderService;
import com.un.ebs.sys.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class OrderTimeOutCheckTask {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private OrderService orderService;

    @Resource
    private UserService userService;

    //@Scheduled(fixedDelay = 1 * 60000 * 60)
    public void OrderSubmitCancel() {
//        List<OrderExt> list = orderService.queryExpire();
//        LoggerFactory.getLogger(this.getClass()).warn("超期订单处理 : " + list.size());
//        for (OrderExt obj : list) {
//            if (StringUtils.isNullOrEmpty(obj.getSubmitUserId())) {
//                continue;
//            }
//            UserContext userContext = userService.markUserContext(obj.getSubmitUserId(), obj.getTenantId(), null);
//            if (userContext == null) {
//                userContext = userService.markUserContext(userService.queryByTenantAdminUserId(obj.getTenantId()), obj.getTenantId(), null);
//                if (userContext == null) {
//                    logger.warn(String.format("撤销过期订单时，没有一个有效的租户【%s】管理员账号可用。", obj.getTenantId()));
//                    continue;
//                }
//            }
//            SecurityUtils.setUserContent(userContext);
//            orderService.submitCancel(obj.getId(), "没有在有效期内支付订金或全款，系统自动取消。");
//        }
    }

}
